#include "particle_system.h"
#include "engine/utils/math_utils.h"

namespace kanon
{
    ParticleMeshComponent::ParticleMeshComponent(uint32_t num_particles)
    {
        particles.clear();
        Particle2D p;
        for (uint32_t i = 0; i < num_particles; ++i)
        {
            float scale = 0.1f;
            // p.position.x = RandomGenerator::random_float(-1.0f * scale, 1.0f * scale);
            // p.position.y = RandomGenerator::random_float(-1.0f * scale, 1.0f * scale);
            p.position = RandomGenerator::random_disk(scale);
            // p.speed.x = RandomGenerator::random_float(-1.0f * scale, 1.0f * scale);
            // p.speed.y = RandomGenerator::random_float(-1.0f * scale, 1.0f * scale);
            p.speed = RandomGenerator::random_disk(2 * scale);
            p.size.x = 0.02f;
            p.size.y = 0.02f;
            p.life = RandomGenerator::random_float(2.0f, 4.0f);
            p.total_life = p.life;
            particles.push_back(p);
        }
    }

    void ParticleMeshComponent::Update(float deltaTime)
    {
        for (auto& p : particles)
        {
            p.life -= deltaTime;
            p.position += p.speed * deltaTime;
        }
    }
}
